Skip to content

Allow int for max_warnings in TOML - #14954

Open
Dmao233 wants to merge 4 commits into
pytest-dev:mainfrom
Dmao233:cursor/max-warnings-toml-int-6b43
Open

Allow int for max_warnings in TOML#14954
Dmao233 wants to merge 4 commits into
pytest-dev:mainfrom
Dmao233:cursor/max-warnings-toml-int-6b43

Conversation

@Dmao233

@Dmao233 Dmao233 commented Aug 31, 2026

Copy link
Copy Markdown

Closes #14953

max_warnings was registered without a type, so native TOML integers (max_warnings = 0) were rejected even though the docs show an unquoted int.

Register it as int | str the same way as truncation_limit_*. _get_max_warnings() treats None as unset so an explicit 0 is not the empty default.

Checklist

  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • closes #14953 in the PR description and the commit.
  • Changelog file changelog/14953.bugfix.rst.
  • Added myself to AUTHORS in alphabetical order.
  • AI assistance is credited in a Co-authored-by trailer.

The max_warnings option was registered without a type (defaulting to
'string'), so integer values in native TOML config raised a TypeError.
It is now registered with type=int | str, accepting both int and string
values in TOML while keeping the string form working for backward
compatibility. An explicit integer 0 is distinguished from the unset
default.

Co-authored-by: Cursor Grok 4.6 <cursoragent@cursor.com>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 31, 2026

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable thank you.

Comment thread testing/test_warnings.py
result.assert_outcomes(passed=1, warnings=1)
assert result.ret == ExitCode.OK

@pytest.mark.filterwarnings("default::UserWarning")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need those automated tests, the int | str mechanism is already tested elsewhere.

Dmao233 and others added 2 commits August 31, 2026 07:21
Co-authored-by: CenFangyu <Dmao233@users.noreply.github.com>
Co-authored-by: CenFangyu <164994318+Dmao233@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

max_warnings rejects the integer shown in the native TOML documentation

3 participants